package com.chat.base.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {
    //状态码 0:成功 其他:失败其他原因
    private int code;

    //返回信息
    private String msg;

    //数据
    private Object data;

    //密钥
    private String key;

    public JsonResult(int code,String msg,Object data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

//    public  JsonResult success(String msg){
//        return new JsonResult(0,msg,null);
//    }
//
    public  JsonResult success(String msg,Object data){
        return new JsonResult(0,msg,data);
    }

    public static JsonResult fail(String msg){
        return new JsonResult(-1,msg,null);
    }

    public static JsonResult fail(int code,String msg){
        return new JsonResult(code,msg,null);
    }

    public static JsonResult success(Object data){
        return new JsonResult(0,"请求成功",data);
    }
}
